<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <!--如果是IE 就以标准渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <!-- 视窗——————响应式布局 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

    <!--当前页面的三要素-->
    <title>运维系统-深中通道AC设备</title>
    <meta name="description" content="聚能优电" />
    <meta http-equiv="keywords" content="聚能优电" />
    <script type="text/javascript" src="../js/verify.js"></script>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="../css/common/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/mainmonitor_szcyj.css" />
</head>

<body>
    <div id="container" class="szcyj">
        <div class="szcyj_01">
            <!--主屏内容-->
            <div class="szcyj_screen">
                <div class="m_title">
                    <a href="JavaScript:history.go(-1);" class="back">
                        <img src="../images/back.svg" alt="">
                    </a>
                    <span class="tit">AC</span>
                </div>
                <div class="m_content">
                    <div class="sb_tit">
                        <span>设备名称:</span>
                        <select id="select" value="" class="arrowdown">
                            <!-- <option value=""></option>
                            <option value="0">北京</option>
                            <option value="1">上海</option>
                            <option value="2">广州</option>
                            <option value="3">深圳</option>
                            <option value="4">杭州</option> -->
                        </select>
                    </div>
                    <div class="flycs cslist">
                        <div class="flycs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">分类一</span>
                        </div>
                        <ul class="list_con" id="flycs_con">
                        </ul>
                    </div>
                    <div class="flecs cslist">
                        <div class="flecs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">分类二</span>
                        </div>
                        <ul class="list_con" id="flecs_con">
                        </ul>
                    </div>

                    <div class="flscs cslist">
                        <div class="flscs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">分类三</span>
                        </div>
                        <ul class="list_con" id="flscs_con">
                        </ul>
                    </div>
                </div>


            </div>
        </div>
    </div>


    <script>
        (function (win, doc) {
            var docEl = doc.documentElement || document.body; //获取HTML标签

            var container = doc.getElementById("container"); //container元素
            //判断是移动端设备还是PC,移动 就采用'orientationchange',横竖屏事件，PC端就采用onresize，窗口改变时间
            var resize =
                "onorientationchange" in win ? "orientationchange" : "resize";

            function rem() {
                docEl.style.fontSize = 100 * (container.clientWidth / 750) + "px";
            }

            //监听'DOMContent事件:DOM加载完成执行,如果DOMContent事件，那么执行rem函数
            doc.addEventListener("DOMContentLoaded", rem, false);

            //win下监听resize事件,如果resize事件，那么执行rem函数
            win.addEventListener(resize, rem, false);
        })(window, document);
    </script>
    <!-- js -->
    <script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
    <script>
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: 'http://112.74.169.99:21021/api/services/app/DeviceService/GetADeviceInfoListByProjectId?id=1&typeid=3',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept",
                        "application/json, text/javascript, */*; q=0.01");
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                },
                success: function (res) {
                    var onoff = 0;
                    var defaulttimer;
                    var changetimer;
                    // console.log("AC数据 请求成功");
                    var data = res.result;
                    var data = [];
                    if (data.length === 0) {
                        $(".m_content").html("暂无数据").css({
                            "font-size": "0.5rem",
                            "text-align": "center",
                            "color": "#fff",
                            "margin-top": "2.5rem"
                        });
                    } else {
                        $("#select").html(eachoption(data));
                        if (onoff == 0) {
                            var optionsdefaultid = $("#select option:selected").attr('valueid');
                            updateData(); // 首次加载立即请求数据
                            defaulttimer = setInterval(updateData, 1000); // 首次加载之后，每1s重新请求一次数据
                            function updateData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: 'http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewACDataByID?Id=' +
                                        optionsdefaultid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader('.AspNetCore.Culture',
                                            'zh-Hans');
                                    },
                                    success: function (res) {
                                        // console.log("首次加载设备数据 请求成功");
                                        $("#flycs_con").html('');
                                        $("#flycs_con").html(eachflycs(res));
                                        $("#flecs_con").html('');
                                        $("#flecs_con").html(eachflecs(res));
                                        $("#flscs_con").html('');
                                        $("#flscs_con").html(eachflscs(res));
                                    },
                                    error: function (res) {
                                        console.log("首次加载设备数据 请求失败");
                                    }
                                });
                            }
                        }


                        // 切换下拉框操作
                        $("#select").change(function () {
                            onoff = 1;
                            clearInterval(defaulttimer);
                            clearInterval(changetimer);
                            var optionschangeid = $(
                                "#select option:selected").attr(
                                'valueid');
                            updateChangeData(); // 首次加载立即请求数据
                            changetimer = setInterval(updateChangeData,
                                1000); // 首次加载之后，每1s重新请求一次数据
                            function updateChangeData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: 'http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewACDataByID?Id=' +
                                        optionschangeid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader(
                                            '.AspNetCore.Culture',
                                            'zh-Hans');
                                    },
                                    success: function (res) {
                                        // console.log("切换设备数据 请求成功");
                                        $("#flycs_con").html('');
                                        $("#flycs_con").html(eachflycs(res));
                                        $("#flecs_con").html('');
                                        $("#flecs_con").html(eachflecs(res));
                                        $("#flscs_con").html('');
                                        $("#flscs_con").html(eachflscs(res));
                                    },
                                    error: function (res) {
                                        console.log("切换设备数据 请求失败");
                                    }
                                })
                            }
                        });
                    }
                },
                error: function (res) {
                    console.log("AC数据 请求失败");
                }
            });


            function eachoption(obj) {
                var str = '';
                if (obj.constructor == Array) {
                    for (var i = 0, len = obj.length; i < len; i++) {
                        var option_value = obj[i].devCN;
                        var option_valueid = obj[i].id;
                        str += `<option value="` + option_value + `" valueid="` +
                            option_valueid + `">` +
                            option_value + `
                        </option>`;
                    }
                    return str;
                }
            }

            // 分类一
            function eachflycs(obj) {
                var str = '';
                str += `<li><span class="con_left">室内温度(℃)</span><span class="con_right">` + obj.result
                    .innerTemperature +
                    `</span></li>`;
                str += `<li><span class="con_left">室外温度(℃)</span><span class="con_right">` + obj.result
                    .condensationTemperature +
                    `</span></li>`;
                str += `<li><span class="con_left">盘管温度(℃)</span><span class="con_right">` + obj.result
                    .coilTemperature +
                    `</span></li>`;
                str += `<li><span class="con_left">排气温度(℃)</span><span class="con_right">` + obj.result
                    .exhaustTemperature +
                    `</span></li>`;
                return str;
            }

            // 分类二
            function eachflecs(obj) {
                obj.result.internalFan = 0 ? '停止' : '运行';
                obj.result.externalFan = 0 ? '停止' : '运行';
                obj.result.compressor = 0 ? '停止' : '运行';
                obj.result.emergencyFan = 0 ? '停止' : '运行';
                var str = '';
                str += `<li><span class="con_left">内风机</span><span class="con_right">` + obj.result
                    .internalFan +
                    `</span></li>`;
                str += `<li><span class="con_left">外风机</span><span class="con_right">` + obj.result
                    .externalFan +
                    `</span></li>`;
                str += `<li><span class="con_left">压缩机</span><span class="con_right">` + obj.result
                    .compressor +
                    `</span></li>`;
                str += `<li><span class="con_left">应急风机</span><span class="con_right">` + obj.result
                    .emergencyFan +
                    `</span></li>`;
                str += `<li><span class="con_left">制冷点</span><span class="con_right">` + obj.result
                    .refrigerationPoint +
                    `</span></li>`;
                str += `<li><span class="con_left">加热点</span><span class="con_right">` + obj.result
                    .heatingPoint +
                    `</span></li>`;
                str += `<li><span class="con_left">高温点</span><span class="con_right">` + obj.result
                    .highTemperaturePoint +
                    `</span></li>`;
                str += `<li><span class="con_left">低温点</span><span class="con_right">` + obj.result
                    .lowTemperaturePoint +
                    `</span></li>`;
                return str;
            }

            // 分类三
            function eachflscs(obj) {
                var str = '';
                str += `<li><span class="con_left">湿度(%RH)</span><span class="con_right">` + obj.result
                    .humidity +
                    `</span></li>`;
                str += `<li><span class="con_left">电流(A)</span><span class="con_right">` + obj.result
                    .electricCurrent +
                    `</span></li>`;
                str += `<li><span class="con_left">交流电压(V)</span><span class="con_right">` + obj.result
                    .acVoltage +
                    `</span></li>`;
                str += `<li><span class="con_left">直流电压(V)</span><span class="con_right">` + obj.result
                    .dcVoltage +
                    `</span></li>`;
                return str;
            }









        });
    </script>

</body>

</html>